home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / importers and exporters / std compression examples / example1.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.3 KB  |  145 lines

  1. /*
  2.     File:        Example1.c
  3.  
  4.     Contains:    Compression of PICT Files
  5.                 
  6.                 The following sample code shows the simplest case of asking the user for a picture file
  7.                 to be compressed, asking them for some compression settings, then compressing the
  8.                 picture file with those settings and quitting.
  9.     
  10.                 This is only a marginally practical example.  A real application would not want to use
  11.                 the various calls exactly in the manner described below.  It is more useful as a
  12.                 demonstration of how the calls behave in different situations.
  13.  
  14.     Written by:     
  15.  
  16.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  17.  
  18.                 You may incorporate this Apple sample source code into your program(s) without
  19.                 restriction. This Apple sample source code has been provided "AS IS" and the
  20.                 responsibility for its operation is yours. You are not permitted to redistribute
  21.                 this Apple sample source code as "Apple sample source code" after having made
  22.                 changes. If you're going to re-distribute the source, we require that you make
  23.                 it clear in the source that the code was descended from Apple sample source
  24.                 code, but that you've made changes.
  25.  
  26.     Change History (most recent first):
  27.                 8/17/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  28.                 12/4/94        khs                changed the format of the file to the new look and feel
  29.  
  30. */
  31. // INCLUDE FILES
  32. #include <menus.h>
  33. #include <fonts.h>
  34. #include <osevents.h>
  35. #include <components.h>
  36. #include <quicktimecomponents.h>
  37.  
  38.  
  39. // FUNCTION PROTOTYPES
  40. void Example1(void);
  41.  
  42.  
  43. // FUNCTIONS
  44. void Example1(void)
  45. {
  46.     ComponentResult result;
  47.     Point where;
  48.     ComponentInstance ci;
  49.     short sref;
  50.     SFTypeList typeList;
  51.     SFReply reply;
  52.  
  53.     //    Tell SFGetFilePreview to center on the best monitor.
  54.  
  55.     where.h = where.v = -2;
  56.  
  57.     //    Show only 'PICT' files in the file list.
  58.  
  59.     typeList[0] = 'PICT';
  60.  
  61.     //    Ask user to select PICT file to be compressed.
  62.  
  63.     SFGetFilePreview(where, "\p", nil, 1, typeList, nil, &reply);
  64.     if (reply.good)
  65.     {
  66.  
  67.         //    If they selected a file, open that file.
  68.  
  69.         result = FSOpen(reply.fName, reply.vRefNum, &sref);
  70.         if (!result)
  71.         {
  72.  
  73.             //    Open the Standard Compression Dialog component.
  74.  
  75.             ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
  76.             if (ci)
  77.             {
  78.  
  79.                 //    If the component opened successfully, set the picture file to
  80.                 //    be the test image shown in the dialog.  Passing nil for srcRect
  81.                 //    means use the entire image.  Passing 0 for testFlags means
  82.                 //    to use the default system method of displaying the test image
  83.                 //    which is currently a combination of cropping and scaling.
  84.  
  85.                 SCSetTestImagePictFile(ci, sref, nil, 0);
  86.  
  87.                 //    We don't need to explicitly set default compression settings
  88.                 //    in this example.  SCCompressPictureFile will see that no
  89.                 //    defaults have been set since the component has been open
  90.                 //    and call SCDefaultPictFileSettings with the test image for you.
  91.                 //    If other defaults did exist, the following call would need to be made:
  92.                 //
  93.                 //        result = SCDefaultPictFileSettings(ci,sref);
  94.  
  95.                 //    Again, because no settings exist yet, SCCompressPictureFile will
  96.                 //    call SCRequestImageSettings automatically to get settings from
  97.                 //    the user.  If other settings had been made previously, the following
  98.                 //    call would have to be made to explicitly ask the user for settings:
  99.                 //
  100.                 //        result = SCRequestImageSettings(ci);
  101.  
  102.                 //    Compress the picture file with the settings chosen by the user.
  103.                 //    The settings include any custom color table found in the source
  104.                 //    picture if still appropriate for the depth chosen by the user.
  105.                 //
  106.                 //    Note that we are able to pass the source file ref for both the
  107.                 //    source and destination picture files.  In this case, the picture
  108.                 //    file will be compressed in place.  It would probably be better to
  109.                 //    ask the user for a name to save the compressed file as, rather than
  110.                 //    compressing it in place.
  111.                 //
  112.                 //    Also note that the result code returned could include scUserCancelled.
  113.  
  114.                 result = SCCompressPictureFile(ci, sref, sref);
  115.  
  116.                 //    Close the Standard Compression Dialog component.
  117.  
  118.                 CloseComponent(ci);
  119.             }
  120.  
  121.             //    Close the source picture file.
  122.  
  123.             FSClose(sref);
  124.         }
  125.     }
  126. }
  127.  
  128.  
  129. // MAIN FUNCTION
  130. void main(void)
  131. {
  132.     InitGraf(&qd.thePort);
  133.     InitFonts();
  134.     FlushEvents(everyEvent, 0);
  135.     InitWindows();
  136.     InitMenus();
  137.     InitDialogs(nil);
  138.     InitCursor();
  139.     MaxApplZone();
  140.  
  141.     Example1();
  142. }
  143.  
  144.  
  145.